package com.zts.base.page.interceptor;

import com.github.miemiedev.mybatis.paginator.domain.Order;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import org.apache.ibatis.session.RowBounds;

import java.util.List;

/**
 * Created by Zhangkh on 2017/6/1.
 */
public class OffsetPageBounds extends PageBounds {

    private int offset;

    public OffsetPageBounds(RowBounds rowBounds) {
        super(rowBounds);

        if (!(rowBounds instanceof PageBounds)) {
            offset = rowBounds.getOffset();
        }
    }

    public OffsetPageBounds(boolean containsTotal, int offset, int limit, List<Order> orders) {
        this(new RowBounds(offset, limit));

        setContainsTotalCount(containsTotal && offset%limit == 0);
        this.orders.addAll(orders);
    }

    @Override
    public int getOffset() {
        return offset;
    }
}
